export default {
  props: {
    options: {
      type: Object,
      default: function() {
        return {
          autoupload: true,
          action: process.env.VUE_APP_BASE_API + '/course/file/upload',
          name: 'file',
          multiple: true
        }
      }
    }
  },
  data() {
    return {
      configs: this.options,
      fileList: [],
      filepath: ''
    }
  },
  created() {
    // console.log('this.$store.getters.courseUploadFileSet -----------' + this.$store.getters.courseUploadFileSet)
  },
  computed: {
    courseUploadFileSet() {
      return this.$store.getters.courseUploadFileSet
    }
  },
  watch: {
    courseUploadFileSet(newVal, oldVal) {
      this.filePath = ''
      this.fileList = []
    }
  },
  methods: {
    on_success(response, file, fileList) {
      this.filepath = response.data
      const result = {
        response,
        file,
        fileList
      }
      this.$emit('backUploaderFile', result)
    },
    on_error(err, file, fileList) { // 文件上传失败时的钩子
      // console.log(err)
      // console.log(file)
      // console.log(fileList)
    },
    on_progress(event, file, fileList) {
      // console.log(event)
      // console.log(file)
      // console.log(fileList)
    },
    handleRemove(file, fileList) {
      this.fileList = []
      // console.log(file, fileList)
      this.$refs.UploaderFile.clearFiles()
    },
    handlePreview(file) {
      // console.log(file)
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${fileList.length} 个文件`)
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    }
  }
}
